package com.alan.activiti.core;

import java.util.List;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

public class Test1 {

	
	private ProcessEngine processEngine=ProcessEngines.getDefaultProcessEngine();
	
	//部署流程定义
	@Test
	public void deploy(){
		Deployment deployment=processEngine.getRepositoryService().createDeployment()
								.addClasspathResource("diagrams/demo_03.bpmn")
								.addClasspathResource("diagrams/demo_03.png")
								.name("demo_03")
								.deploy();
		
		System.out.println("路程部署ID："+deployment.getId());
		System.out.println("路程部署Name："+deployment.getName());
	}
	
	//删除流程定义
	@Test
	public void deleteProDef(){
		processEngine.getRepositoryService().deleteDeployment("5001",true);
	}
	
	//开始流程
	@Test
	public void start(){
		ProcessInstance pro = processEngine.getRuntimeService()
		.startProcessInstanceByKey("demo_03");
		System.out.println("流程开始了，实例ID为："+pro.getId());
		System.out.println("流程开始了，流程定义ID为："+pro.getProcessDefinitionId());
		
	}
	
	//查找某人可以完成的任务
	@Test
	public void findTask(){
		List<Task> tasks = processEngine.getTaskService().createTaskQuery().taskAssignee("zhangsan").list();
		for (Task task : tasks) {
			System.out.println("开始时间："+task.getCreateTime());
			System.out.println("委托人："+task.getAssignee());
			System.out.println("任务名称："+task.getName());
			System.out.println("任务ID："+task.getId());
			System.out.println("流程实例ID："+task.getProcessInstanceId());
		}
		
	}
	
	//执行任务
	@Test
	public void excuteTask() {
		processEngine.getTaskService().complete("20004");
	}
	
	
	
}
